﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace KTSonline.administrator
{
    public partial class MayQuayPhim : System.Web.UI.Page
    {
        public String getImageURL(object b)
        {
            return Global.AdminPage_getImageURL(b);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("Login.aspx");
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("Login.aspx");
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("Login.aspx");

            DetailsView1.Visible = true;
            DetailsView1.ChangeMode(DetailsViewMode.Edit);
            GridView1.Visible = false;
            option.Visible = false;
        }

        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("Login.aspx");
        }

        protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
        {
            Response.Redirect("MayQuayPhim.aspx");
        }

        protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("Login.aspx");
            if (e.CancelingEdit)
            {
                DetailsView1.Visible = false;
                option.Visible = true;
                GridView1.Visible = true;
                btnAdd.Visible = true;
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("Login.aspx");
            DetailsView1.Visible = true;
            DetailsView1.ChangeMode(DetailsViewMode.Insert);
            KTSonlineDataContext db = new KTSonlineDataContext();
            int number = db.IDENTITY_CONTROLs.Where(c => c.tenbang == "MAY_QUAY_PHIM").First().sothutu + 1;
            String id = "MQP" + number.ToString("0000");
            ((TextBox)DetailsView1.FindControl("txtid")).Text = id;
            btnAdd.Visible = false;
            option.Visible = false;
            GridView1.Visible = false;
        }

        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            if (Session["admin"] == null)
                Response.Redirect("Login.aspx");
        }

        protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            KTSonlineDataContext db = new KTSonlineDataContext();
            db.IDENTITY_CONTROLs.Where(c => c.tenbang == "MAY_QUAY_PHIM").First().sothutu++;
            db.SubmitChanges();
            Response.Redirect("MayQuayPhim.aspx");
        }
    }
}
